import route from "@/router"
import { setStorage,getStorage,removeAllStorage } from "@/unitils/storage";

export default{
    namespaced:true,
    state:{
        userInfo:getStorage("userInfo") ||null
    },
    mutations:{
        setuserInfo(stata, userInfo){
            let  date = new Date().getTime() + (3 * 24 * 60 * 60 * 1000);
            let user = {...userInfo,date}
            stata.userInfo = user;
            setStorage("userInfo", user);
        }
    },
    actions:{
        async login(context,data){
            await this.commit("user/setuserInfo", data);
            route.push('/').catch(()=>{
                console.log("重复进入路由")
            });


        },
        async loginOut(context){
            removeAllStorage();
            // store.replaceState(createStore(options).state);
            route.go(0);
            
        },
    }
}